var businessLogic = require('../../../utils/NetWork/Model/NewsbusinessLogic.js')
var WxParse = require('../../../utils/Component/wxParse/wxParse.js');
var common = require('../../../utils/common.js')
var orgid = common.getStorageSync("orgid")
var userid = common.getStorageSync("userid")
 function userData() {
  var arr = {

  }
  return arr
} 

module.exports = {
   userData: userData, 
}


Page({
  // 页面初始数据
  data: {
    post_title: [],
    title:"",
    ryid2:"",
    num: 1
  },
  onLoad: function (options) {
    var scrollHeight = scrollHeight;
    wx.getSystemInfo({
      success: function (res) {
        scrollHeight = res.windowHeight
      }
    });
    this.setData({
      ryid2: options.id,
      scrollHeight: scrollHeight,
    })
 
    this.news();
  },
  bindDownLoad: function () {
    if (this.data.lenpage > this.data.num) {
      var di = this.data.num;
      var di = di + 1;
      this.setData({
        num: di
      });
    } else {
      common.showToast("加载全部", "loading");
    }
    //common.showToast("到底了", "loading");

  },
  //2.1.2新闻列表
  news: function () {
    common.showToast("加载中", "loading");
    // 第二步 传参
    let params = { "page": this.data.num, "num": 5, "orgid": orgid, "userid": userid, "searchField": "orgid,channel", "searchValue": "" + orgid + "," + this.data.ryid2 + ""}
    //第三步 调用接口y
    businessLogic.NewsList(params, (res) => {
      //第五步 把获取的值，传入data
      var n = [];
      for (var i = 0; i < res.infos.length; i++) {
        if (res.infos[i].onclick > 999999) {
          // n[i] = Math.round((res.infos[i].onclick / 100000) * 100) / 100;
          res.infos[i].onclick = 999999 + "+";
        } else {
          res.infos[i].onclick = res.infos[i].onclick + "次";
        }
      }
      var bbb = this.data.post_title;
      for (var a = 0; a < res.infos.length; a++) {
        bbb.push(res.infos[a]);
      } 
      this.setData({
        post_title: bbb,
        lenpage: res.page.pages
      });

    });

  },
  bindKeyInput: function (e) {
    this.setData({
      title: e.detail.value
     
    })
  },
  search2: function (event) {
    let params = { "page": 1, "num": 5, "orgid": orgid, "userid": userid, "searchField": "title,orgid,channel", "searchValue": "" + this.data.title + "," + orgid + "," + this.data.ryid2 + "" }
    businessLogic.NewsList(params, (res) => {
      var res = res.infos
      this.setData({
        post_title: res
      });
    });
  },

  

  // 跳转至详情页
  alreadyOrder: function (event) {
    //跳转
    wx.navigateTo({
      url: "../alreadyOrder/alreadyOrder?id=" + this.data.ryid2
    });
  },
  newsDetailPic: function (event) {
    //跳转
    wx.navigateTo({
      url: "../newsDetailPic/newsDetailPic?id=" + event.currentTarget.dataset.id
    });
  
  }, 
})